package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CourseSchedules;
import com.ruoyi.system.service.ICourseSchedulesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 环保课程-课时Controller
 * 
 * @author zrj
 * @date 2025-07-15
 */
@RestController
@RequestMapping("/system/schedules")
public class CourseSchedulesController extends BaseController
{
    @Autowired
    private ICourseSchedulesService courseSchedulesService;

    /**
     * 查询环保课程-课时列表
     */
    @PreAuthorize("@ss.hasPermi('system:schedules:list')")
    @GetMapping("/list")
    public TableDataInfo list(CourseSchedules courseSchedules)
    {
        startPage();
        List<CourseSchedules> list = courseSchedulesService.selectCourseSchedulesList(courseSchedules);
        return getDataTable(list);
    }

    /**
     * 导出环保课程-课时列表
     */
    @PreAuthorize("@ss.hasPermi('system:schedules:export')")
    @Log(title = "环保课程-课时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CourseSchedules courseSchedules)
    {
        List<CourseSchedules> list = courseSchedulesService.selectCourseSchedulesList(courseSchedules);
        ExcelUtil<CourseSchedules> util = new ExcelUtil<CourseSchedules>(CourseSchedules.class);
        util.exportExcel(response, list, "环保课程-课时数据");
    }

    /**
     * 获取环保课程-课时详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:schedules:query')")
    @GetMapping(value = "/{scheduleId}")
    public AjaxResult getInfo(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(courseSchedulesService.selectCourseSchedulesByScheduleId(scheduleId));
    }

    /**
     * 新增环保课程-课时
     */
    @PreAuthorize("@ss.hasPermi('system:schedules:add')")
    @Log(title = "环保课程-课时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CourseSchedules courseSchedules)
    {
        return toAjax(courseSchedulesService.insertCourseSchedules(courseSchedules));
    }

    /**
     * 修改环保课程-课时
     */
    @PreAuthorize("@ss.hasPermi('system:schedules:edit')")
    @Log(title = "环保课程-课时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CourseSchedules courseSchedules)
    {
        return toAjax(courseSchedulesService.updateCourseSchedules(courseSchedules));
    }

    /**
     * 删除环保课程-课时
     */
    @PreAuthorize("@ss.hasPermi('system:schedules:remove')")
    @Log(title = "环保课程-课时", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scheduleIds}")
    public AjaxResult remove(@PathVariable Long[] scheduleIds)
    {
        return toAjax(courseSchedulesService.deleteCourseSchedulesByScheduleIds(scheduleIds));
    }
}
